﻿namespace GoodAdmin.Web.Core;


/// <summary>
/// 配置信息控制器
/// </summary>
[ApiDescriptionSettings("System", Tag = "配置管理")]
[Route("/system/config")]
public class ConfigController:IDynamicApiController
{
    private readonly IConfigService _configService;

    public ConfigController(IConfigService configService)
	{
        _configService = configService;
    }

    #region  GET
    /// <summary>
    /// 获取配置明细
    /// </summary>
    /// <param name="Category"></param>
    /// <param name="configKey"></param>
    /// <returns></returns>
    [HttpGet("getConfigInfo")]
    [DisplayName("获取配置明细")]
    public async Task<SimpleConfig> GetConfigInfo([FromQuery] string Category, [FromQuery] string configKey)
    {
        return await _configService.GetConfigInfo(Category, configKey);
    }

    /// <summary>
    /// 获取配置列表
    /// </summary>
    /// <param name="Category"></param>
    /// <returns></returns>
    [HttpGet("getConfigList")]
    [DisplayName("获取配置列表")]
    public async Task<List<SimpleConfig>> GetConfigListByCategory(string Category)
    {
        return await _configService.GetConfigListByCategory(Category);
    }

    /// <summary>
    /// 获取系统配置
    /// </summary>
    /// <returns></returns>
    [HttpGet("getSystemConfig")]
    [DisplayName("获取系统配置")]
    public async Task<ConfigOutput> GetSystemConfig()
    {
        return await _configService.GetSystemConfig();
    }

    /// <summary>
    /// 分页查询
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet("page")]
    [DisplayName("分页查询")]
    public async Task<SqlSugarPagedList<SysConfig>> GetConfigPageList([FromQuery] ConfigPageInput input)
    {
        return await _configService.GetConfigPageList(input);
    }
    #endregion

    #region POST
    /// <summary>
    /// 添加配置
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost("add")]
    [DisplayName("添加配置")]
    public async Task AddConfig(ConfigAddInput input)
    {
        await _configService.AddConfig(input);
    }

    /// <summary>
    /// 删除配置
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost("delete")]
    [DisplayName("删除配置")]
    public async Task DeleteConfig(BaseIdInput input)
    {
        await _configService.DeleteConfig(input);
    }

    /// <summary>
    /// 更新配置
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost("update")]
    [DisplayName("更新")]
    public async Task UpdateConfig(ConfigUpdateInput input)
    {
        await _configService.UpdateConfig(input);
    }

    /// <summary>
    /// 更新系统配置
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost("updateSystemConfig")]
    [DisplayName("更新系统配置")]
    public async Task UpdateSystemConfig(SystemConfigUpdateInput input)
    {
        await _configService.UpdateSystemConfig(input);
    }
    #endregion
}